from models.dao import crimes_dao
from models.database import SessionLocal

def getCrimes(skip: int = 0, limit: int = 100):
    with SessionLocal() as db:
        crimes = crimes_dao.getCrimes(db, skip=skip, limit=limit)
        return [c.to_dict() for c in crimes]

def getCrime(crime_id: str):
    with SessionLocal() as db:
        crimeModel = crimes_dao.getCrime(db, crime_id=crime_id)
        if crimeModel is None:
            return None
        return crimeModel.to_dict()

def createCrime(crime_data: dict):
    with SessionLocal() as db:
        # In a real application, you would have more business logic here,
        # like validation, sending notifications, etc.
        newCrimeModel = crimes_dao.createCrime(db, crime_data)
        if newCrimeModel is None:
            return None
        return newCrimeModel.to_dict()

def updateCrime(crime_id: str, crime_data: dict):
    with SessionLocal() as db:
        updatedCrimeModel = crimes_dao.updateCrime(db, crime_id=crime_id, crime=crime_data)
        if updatedCrimeModel is None:
            return None
        return updatedCrimeModel.to_dict()

def deleteCrime(crime_id: str):
    with SessionLocal() as db:
        return crimes_dao.deleteCrime(db, crime_id=crime_id)
